package com.telecomyt.jwportal.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.telecomyt.jwportal.R;

/**
 * @author created by chengDa
 * @time 2020/8/28  15:20
 * @description
 */
public class SearchDialog extends Dialog implements View.OnClickListener {
    private TextView mTextView, mTextView1;
    private LinearLayout mLinearLayout;

    public SearchDialog(Context context, ClickListener listener) {
        super(context, R.style.DialogStyle);
        setCustomDialog();
        this.listener = listener;
    }

    private void setCustomDialog() {
        View mView = LayoutInflater.from(getContext()).inflate(R.layout.view_dialog_input, null);
        mLinearLayout = findViewById(R.id.mLinearLayout);
        mTextView = (TextView) mView.findViewById(R.id.mTextView);
        mTextView1 = (TextView) mView.findViewById(R.id.mTextView1);
        mTextView.setOnClickListener(this);
        mTextView1.setOnClickListener(this);
        getWindow().setGravity(Gravity.BOTTOM);//设置显示在底部
        super.setContentView(mView);
    }


    private ClickListener listener;

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.mTextView:
                listener.onRise(mLinearLayout);
                break;
            case R.id.mTextView1:
                listener.down(mLinearLayout);
                break;
        }
    }


    public interface ClickListener {
        void onRise(LinearLayout mLinearLayout);

        void down(LinearLayout mLinearLayout);

    }

    @Override
    public void show() {
        super.show();
        /**
         * 设置宽度全屏，要设置在show的后面
         */
        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
        layoutParams.gravity = Gravity.BOTTOM;
        layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
        layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
        getWindow().getDecorView().setPadding(0, 0, 0, 0);
        getWindow().setAttributes(layoutParams);
    }
}

